package com.cn.dream_order_server.controller;

import com.cn.dream_order_server.pojo.OrderOrder;
import com.cn.dream_order_server.service.OrderOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
public class OrderOrderController {


    @Autowired
    private OrderOrderService orderOrderService;

    @RequestMapping("/wlcGetOrderTotalPageByUser")
    public String wlcGetOrderTotalPageByUser(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserId("1", pageNo, pageSize);
        if(pageInfo.getPages()<1){
            pageInfo.setPages(1);
        }

        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-total-page";
    }

    @RequestMapping("/wlcGetOrderTotalPageByUser1")
    public String wlcGetOrderTotalPageByUser1(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserId("1", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-total-page::div1";
    }

    @RequestMapping("/wlcGetOrderPayment")
    public String wlcGetOrderPayment(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","1", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-payment";
    }

    @RequestMapping("/wlcGetOrderPayment1")
    public String wlcGetOrderPayment1(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","1", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-payment::div1";
    }


    @RequestMapping("/wlcGetOrderWaitForReceiving")
    public String wlcGetOrderWaitForReceiving(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","2", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-wait-for-receiving";
    }


    @RequestMapping("/wlcGetOrderWaitForReceivingLoad")
    public String wlcGetOrderWaitForReceivingLoad(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","2", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-wait-for-receiving::div1";
    }

    @RequestMapping("/wlcGetOrderTotalPageByUserAndAccomplish")
    public String wlcGetOrderTotalPageByUserAndAccomplish(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","3", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-total-page-Accomplish";
    }


    @RequestMapping("/wlcGetOrderTotalPageByUserAndAccomplish1")
    public String wlcGetOrderTotalPageByUserAndAccomplish1(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","3", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-total-page-Accomplish::div1";
    }

    @RequestMapping("/wlcGetOrderTotalPageByUserAndCancel")
    public String wlcGetOrderTotalPageByUserAndCancel(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","4", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-total-page-Cancel";
    }

    @RequestMapping("/wlcGetOrderTotalPageByUserAndCancelLoad")
    public String wlcGetOrderTotalPageByUserAndCancelLoad(Map map,Integer pageNo,Integer pageSize){

        if(pageNo == null || pageNo < 1 ){
            pageNo = 1;
        }
        if(pageSize == null ){
            pageSize = 10;
        }
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<OrderOrder> pageInfo = orderOrderService.getOrderOrderListByUserIdAndOrdertypeId("1","4", pageNo, pageSize);


        map.put("pageNo",pageInfo.getPageNum());
        map.put("totalPages",pageInfo.getPages());
        map.put("orderOrderList",pageInfo.getList());
        map.put("getPages",pageInfo.getPages());
        map.put("pageInfo",pageInfo);
        return "order-total-page-Cancel::div1";
    }



    @RequestMapping("/wlcDoConfirmReceipt")
    @ResponseBody
    public Object wlcDoConfirmReceipt(String orderId,Integer pageNo,Integer thisPage){
        Boolean flag = false;
        if(orderOrderService.doConfirmReceipt(orderId,pageNo,thisPage,"1")!=null){
            flag = true;
        }

        return flag;
    }



    @RequestMapping("/wlcDoDeleteShoppingOrder")
    @ResponseBody
    public Object wlcDoDeleteShoppingOrder(String orderId,Integer pageNo,Integer thisPage){
        Boolean flag = false;
        if(orderOrderService.doDeleteShoppingOrder(orderId,pageNo,thisPage,"1")!=null){
            flag = true;
        }

        return flag;
    }

}
